-
Notifications
You must be signed in to change notification settings - Fork 19
stop using Base.convert #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Probably it would be better to move the "no conversion needed" next to the 2 to 3 arg method, and make it 2 arg, avoiding the geomtrait call. |
And expand the example a bit.
|
@rafaqz and I discussed this in the past and we settled for using Base.convert. While harder to implement, it enables more automatic conversions and it users know it already. In terms of quick fallback, for LibGEOS, I did the following: JuliaGeo/LibGEOS.jl@b6902e1. |
|
I haven't tested the GeometryBasics code yet, but in your example:
The conversion would still work for any non |
No, it would only work for geometries for which Any is the most specific method it hits, which is something that cannot be relied on.
I'm talking about the generic GeoInterface conversion, which is the only one I implemented. I was testing using GeoJSON as source geometries. |
|
So does that mean that this function in this package: convert(T, geom) = convert(T, geomtrait(geom), geom)Accidentally defined
For those reasons I would've also preferred struct LineString <: AbstractVector{Float64}
# [p1.x p1.y p2.x p2.y ...]
coords::Vector{Float64}
endright? For types like this it can be useful to make them an AbstractVector. |
|
Yeah, its a bit annoying because of the manual definitions required. But I think thats nice to have for all geometry types?
|
Sorta. I started out with convert and forgot to change all references to Base.convert. |
|
I think it would be great to make a decision here. Personally, I am not in favor of overloading |
|
Hmm I'm tending to agree with you ans @visr now, maybe |
|
Agreed, and maybe also |
|
Ok. well lets put in some time to get I don't think we can delete the |
Why not? There is only one method add to Base.convert, which always throws an error: Base.convert(T::Type, ::AbstractGeometryTrait, geom) = error("..")If we remove it, calling this methods will still throw an error, just a MethodError instead of an ErrorException. |
| have implemented GeoInterface. | ||
| Create a `CustomGeom` from any `geom` that implements the GeoInterface. | ||
| """ | ||
| convert(T, geom) = convert(T, geomtrait(geom), geom) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this was changed to Base.convert, it would be highly problematic -- but not just because of potential ambiguities this introduces, but also because it would invalidate basically every method in the system, forcing Julia to recompile tons of stuff. So basically after using GeoInterface everything would have the "first time invocation overhead" again. That'd be really bad, esp. now that Julia 1.9 or 1.10 will add native code caching (i.e. generated machine code will be cached as part of precompilation -- speeding up TTFX quite a bit -- unless packages kill the benefit by invalidating methods...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noone suggested that you may misunderstand this PR.
If we invalidate anything with convert it would be with type pyracy, which is much higher up the list of "things not to do".
But we are all on board with using the package convert it's just what to do with the fact that we already have implementations of Base.convert in the wild.
| end | ||
| coordinates(t::AbstractFeatureCollectionTrait, fc) = [coordinates(f) for f in getfeature(fc)] | ||
|
|
||
| Base.convert(T::Type, ::AbstractGeometryTrait, geom) = error("Conversion is enabled for type $T, but not implemented. Please report this issue to the package maintainer.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is weird, but not actually a performance problem because the Julia compiler will never insert invocations to a three-argument Base.convert method
Following discussion in #49.
I tried implementing Base.convert as suggested by the GeoInterface docs for GeometryBasics, testing with GeoJSON geometries.
The first method is needed to send the 2-arg convert through the 3-arg method with the trait argument.
This method is
geom::Any, so if there are any convert methods with more specific types already defined, I cannot hit this anymore. This was the case with trying toconvert(GeometryBasics.Point, p::GeoJSON.Point).GeoJSON.Pointis anAbstractVector, and there is a method defined for those already. However that method doesn't work (since the number of dimensions, 2 or 3, is not statically known).So here I removed all
Base.convertusages from docs and examples. There is already aGeoInterface.convertmethodThat works well, and I figured we don't need to ask developers to add a fast passthrough if we can define it ourselves in fallback.jl: